package com.example.administrator.mobilesafe.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.mobliesafe.R;

/**
 * Created by Administrator on 2015/8/26.
 */

public class SettingItemView extends RelativeLayout {
    private TextView tv_desc;
    private CheckBox cb_status;
    private String desc_on;
    private String desc_off;
    private String title;
    TextView tv_title;
    public SettingItemView(Context context) {
        super(context);
        iniView(context);
    }

    private void iniView(Context context) {
        View.inflate(context, R.layout.setting_item_view, this);
        tv_desc= (TextView) findViewById(R.id.tv_desc);
        cb_status = (CheckBox)findViewById(R.id.cb_status);
        tv_title = (TextView) findViewById(R.id.tv_title);
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        iniView(context);
        desc_on = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","desc_on");
        desc_off = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","desc_off");
        title = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","tv_title");
        tv_title.setText(title);
    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        iniView(context);
    }
    public boolean isChecked(){
        return cb_status.isChecked();
    }
    public void setChecked(boolean checked){
        if(checked){
            setDesc(desc_on);
            cb_status.setChecked(true);
        }else {
            setDesc(desc_off);
            cb_status.setChecked(false);
        }
    }
    public void setDesc(String text){
        tv_desc.setText(text);
    }

}
